package com.gasolinator.a.app.helper;

import com.gasolinator.a.app.GasolinatorStation;
import com.gasolinator.a.augmented_reality.ui.GasolinatorMarker;
import com.gasolinator.a.augmented_reality.ui.Marker;

import java.util.Comparator;
/**
 * Created by IntelliJ IDEA.
 * User: fjhidalgo
 * Date: 9/12/11
 * Time: 10:03
 * To change this template use File | Settings | File Templates.
 */
public class MarkersComparator implements Comparator<Marker> {
    String combustible;
    int type;

    public MarkersComparator(int type, String combustible) {
        this.type = type;
        this.combustible = combustible;
    }

    public int compare(Marker gasolinatorMarker1, Marker gasolinatorMarker2)
    {
        GasolinatorStation gasolinatorStation1 = ((GasolinatorMarker)gasolinatorMarker1).getStation();
        GasolinatorStation gasolinatorStation2 = ((GasolinatorMarker)gasolinatorMarker2).getStation();

        Double price1 = Double.valueOf(gasolinatorStation1.getPrice(combustible));
        Double price2 = Double.valueOf(gasolinatorStation2.getPrice(combustible));

        Double distance1 = gasolinatorStation1.getDistance();
        Double distance2 = gasolinatorStation2.getDistance();

        Boolean isFavorite1 = Boolean.valueOf(gasolinatorStation1.getFavorite());
        Boolean isFavorite2 = Boolean.valueOf(gasolinatorStation2.getFavorite());

        int i;
        switch (type) {
            case 2: //FAVORITES
                if (isFavorite1.compareTo(isFavorite2) == 0) {
                    i = price1.compareTo(price2);
                }
                else {
                    i = isFavorite1.compareTo(isFavorite1);
                }
                break;
            case 1: //DISTANCE
                if (distance1.compareTo(distance2) == 0) {
                    i = price1.compareTo(price2);
                }
                else {
                    i = distance1.compareTo(distance2);
                }
                break;
            default: //PRICE
                if (price1.compareTo(price2) == 0) {
                    i = distance1.compareTo(distance2);
                }
                else {
                    i = price1.compareTo(price2);
                }
        }
        return i;
    }
}
